﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using NHibernate.Validator.Constraints;

namespace DataStore.Domain
{
    /// <summary>
    /// Document categories
    /// </summary>
    [Serializable]
    public class Category : IDataErrorInfo
    {
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public virtual Guid Id { get; set; }
        /// <summary>
        /// Gets or sets the category text.
        /// </summary>
        /// <value>The text.</value>
        [NotNullNotEmpty(Message = "Category text cannot be empty")]
        public virtual string Text { get; set; }

        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <returns>
        /// The error message for the property. The default is an empty string ("").
        /// </returns>
        /// <param name="columnName">The name of the property whose error message to get. </param>
        string IDataErrorInfo.this[string columnName]
        {
            get { return GetValidationError(columnName); }
        }

        /// <summary>
        /// Gets an error message indicating what is wrong with this object.
        /// </summary>
        /// <returns>
        /// An error message indicating what is wrong with this object. The default is an empty string ("").
        /// </returns>
        string IDataErrorInfo.Error
        {
            get { return null; }
        }

        string GetValidationError(string propertyName)
        {
            if (Array.IndexOf(_validatedProperties, propertyName) < 0)
                return null;

            string error = string.Empty;

            switch (propertyName)
            {
                default:
                    Debug.Fail("Unexpected property being validated on CatalogItem: ", propertyName);
                    break;
            }

            return error;
        }

        readonly string[] _validatedProperties =
        {
            
        };

        public virtual bool IsValid
        {
            get
            {
                foreach (string property in _validatedProperties)
                {
                    if (GetValidationError(property) != string.Empty)
                    {
                        return false;
                    }
                }

                return true;
            }
        }
    }
}
